package utilitarios;

import java.awt.Component;
import java.awt.Dimension;
import static java.awt.Frame.ICONIFIED;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 *
 * @author WELISSON
 */
public class Bounds {

    //variaveis usadas para armazenar as medidas e posições
    public int width, height, left, top;

    //metodo utilizado para pegar as medidas e posiçoes do Component passado como
    //parametro
    public void setAllScreenBounds(Component component) {
        Insets in = Toolkit.getDefaultToolkit().getScreenInsets(component.getGraphicsConfiguration());
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

        width = d.width - (in.left + in.right);
        height = d.height - (in.top + in.bottom);
        left = in.left;
        top = in.top;
    }
    
    public JLabel botaoFechar(final double posX, final JFrame frame){
        final JLabel lab = new JLabel();
        lab.setBounds((int)posX - 40, (int)0, 40, 40);
        final ImageIcon img, imgOver;
        img = new ImageIcon((getClass().getResource("/imagens/sair.fw.png")));
        imgOver = new ImageIcon((getClass().getResource("/imagens/sair_over.fw.png")));
        
        lab.setIcon(img);
        //System.out.println(width+" "+heigth);
        lab.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent evt){
                //veriifica se depois de clicado o mouse nao foi arrastado para fora do botão
                if(evt.getX() < lab.getAlignmentX() || evt.getX() > 40+lab.getAlignmentX()){
                    return;
                }
                if(evt.getY() < lab.getAlignmentY() || evt.getY() > 40+lab.getAlignmentY()){
                    return;
                }
                System.exit(0);
            }
            
        });
        
        lab.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {
                lab.setIcon(imgOver);
            }
            @Override
            public void mouseExited(MouseEvent e) {
                lab.setIcon(img);
            }
            
        });
        
        return lab;
    }
    
    public JLabel botaoMinimizar(final double posX, final JFrame frame){
        final JLabel lab = new JLabel();
        lab.setBounds((int)posX - 82, (int)0, 40, 40);
        final ImageIcon img, imgOver;
        img = new ImageIcon((getClass().getResource("/imagens/minimizar.fw.png")));
        imgOver = new ImageIcon((getClass().getResource("/imagens/minimizar_over.fw.png")));
        
        lab.setIcon(img);
        //System.out.println(width+" "+heigth);
        lab.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent evt){
                //veriifica se depois de clicado o mouse nao foi arrastado para fora do botão
                if(evt.getX() < lab.getAlignmentX() || evt.getX() > 40+lab.getAlignmentX()){
                    return;
                }
                if(evt.getY() < lab.getAlignmentY() || evt.getY() > 40+lab.getAlignmentY()){
                    return;
                }
                frame.setExtendedState(ICONIFIED);
            }
        });
        
        lab.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {
                lab.setIcon(imgOver);
            }
            @Override
            public void mouseExited(MouseEvent e) {
                lab.setIcon(img);
            }
            
        });
        
        return lab;
    }
    
    public JLabel botaoFechar(final double posX, final JDialog frame){
        final JLabel lab = new JLabel();
        lab.setBounds((int)posX - 40, (int)0, 40, 40);
        final ImageIcon img, imgOver;
        img = new ImageIcon((getClass().getResource("/imagens/sair.fw.png")));
        imgOver = new ImageIcon((getClass().getResource("/imagens/sair_over.fw.png")));
        
        lab.setIcon(img);
        //System.out.println(width+" "+heigth);
        lab.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent evt){
                //veriifica se depois de clicado o mouse nao foi arrastado para fora do botão
                if(evt.getX() < lab.getAlignmentX() || evt.getX() > 40+lab.getAlignmentX()){
                    return;
                }
                if(evt.getY() < lab.getAlignmentY() || evt.getY() > 40+lab.getAlignmentY()){
                    return;
                }
                frame.dispose();
            }
            
        });
        
        lab.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {
                lab.setIcon(imgOver);
            }
            @Override
            public void mouseExited(MouseEvent e) {
                lab.setIcon(img);
            }
            
        });
        
        return lab;
    }
    
    
}

